package com.gc.server.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import com.gc.server.entity.PlanEntity;
import com.gc.server.service.PlanService;
import com.yf.response.R;


/**
 * 周计划Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Tue Mar 10 11:17:45 CST 2020
 */
@RestController
@RequestMapping("/plan")
public class PlanController {
    @Autowired
    private PlanService planService;

    /**
     * 列表周计划
     */
    @RequestMapping("/list")
    @RequiresPermissions("plan:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<PlanEntity> planList = planService.queryList(params);
        return R.ok(new PageInfo(planList));
    }

    /**
     * 查看周计划
     */
    @SysLog("查看周计划")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("plan:info")
    public R info(@PathVariable("id") Long id) {
        PlanEntity plan = planService.get(id);

        return R.ok(plan);
    }

    /**
     * 保存周计划
     */
    @SysLog("保存周计划")
    @RequestMapping("/save")
    @RequiresPermissions("plan:save")
    public R save(PlanEntity plan) {
        planService.save(plan);

        return R.ok(plan);
    }

    /**
     * 修改周计划
     */
    @SysLog("修改周计划")
    @RequestMapping("/update")
    @RequiresPermissions("plan:update")
    public R update(PlanEntity plan) {
        planService.update(plan);

        return R.ok(plan);
    }

    /**
     * 删除周计划
     */
    @SysLog("删除周计划")
    @RequestMapping("/delete")
    @RequiresPermissions("plan:delete")
    public R delete(Long[]ids) {
        planService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有周计划
     */
    @SysLog("所有周计划")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<PlanEntity> planList = planService.queryList(params);

        return R.ok(planList);
    }

    /**
    @ModelAttribute
    public SearchParam<PlanEntity> searchParam(SearchParam<PlanEntity> params, PlanEntity plan) {
        if (plan != null) {
            params.setEntity(plan);
        }

        return params;
    }
 **/
    /***********自定义开始***********/
}
